package com.cyy.ultra_ptr_demo.avtivity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.cyy.ultra_ptr_demo.R;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;

public class RefreshActivity extends AppCompatActivity {

    @InjectView(R.id.textview)
    TextView textview;
    @InjectView(R.id.ptr_text)
    PtrClassicFrameLayout ptrText;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_refresh);
        ButterKnife.inject(this);

               //可以设置计入的时候自动刷新功能
        ptrText.postDelayed(new Runnable() {
            @Override
            public void run() {
                ptrText.autoRefresh();//自动刷新
            }
        }, 500);

        ptrText.setPtrHandler(new PtrDefaultHandler() {
            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                ptrText.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ptrText.refreshComplete();
                    }
                }, 2000);
            }
        });
    }

    @OnClick(R.id.ptr_text)
    public void onClick() {
        //点击触发刷新
        ptrText.autoRefresh();
    }
}
